package com.example.testdemo.controller;

import ch.qos.logback.core.util.StringUtil;
import jakarta.servlet.http.HttpSession;
import org.apache.catalina.Session;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/user")
@RestController
public class userController {
    @RequestMapping("/login")
    public boolean login(String userName,String password,HttpSession session){
        if(!StringUtils.hasLength(userName)||!StringUtils.hasLength(password)){
            //使用这个可以对字符串是否为空进行判定
            return false;
        }
        if("zhangsan".equals(userName)&&"123456".equals(password)){
            //先默认用户名和密码是固定的
            //正确就是要存储Session
            session.setAttribute("userName",userName);
            session.setAttribute("password",password);
            return true;
        }
        return false;
    }

    @RequestMapping("/getUserInfo")
    public String getSession(HttpSession session){
       return (String) session.getAttribute("userName");
    }
}
